package demo;

import java.util.*;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-24
 */

public class Main {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        list.add("abc");
        list.add("fawinf");
        list.add("wabfhjaf");
        list.add("abc");
        list.add("iwufbad");

        //反转、交换、替换
        System.out.println(list);
        Collections.reverse(list);
        System.out.println(list);

        Collections.swap(list, 0, 1);
        System.out.println(list);

        Collections.replaceAll(list, "abc", 666);
        System.out.println(list);

        //排序、最大最小
        for (int i = 0; i < 3; i++) {
            Collections.shuffle(list);
            System.out.println(list);
        }
        System.out.println();
        Collections.sort(list, new Cmp());
        System.out.println(list);
        System.out.println();
        System.out.println(Collections.max(list, new Cmp()));
        System.out.println(Collections.min(list, new Cmp()));


        //出现次数、拷贝
        System.out.println(Collections.frequency(list, "abc"));
        System.out.println();

        ArrayList cp = new ArrayList(5);
        //Collections.copy(cp, list);
        cp.addAll(list);
        list.set(0, 999999999);
        System.out.println(list);
        System.out.println(cp);
    }
}
class Cmp implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        return ((String) o1).length() - ((String) o2).length();
    }
}
